<?php
/**
 * 后台平台银行卡表操作模型
 */
class MBankInfo extends MY_Model {

	protected $table = 'bank_info';
	private $filter = array();

    function __construct() {
        parent::__construct();
    }
    
	public function getQuery($limit=null){
		$this->db->select('*');
		$this->db->from($this->table);
		if($limit != null)
			$this->db->limit($limit['limit'],$limit['offset']);

		$this->formfilter->doFilter();
		$rtn = $this->db->get();
		return $rtn;
	}

	/**
     * 获取用户列表
     */    
	public function getList($limit){
		$result = $this->getQuery($limit)->result();
		return $result;
	}
	
	/**
	 * 通过code 银行编号查找
	 */
	public function getByCode($code){
	    $this->db->where('code',$code);
	    $row = $this->db->get($this->table)->row_array();
	    if($row){
	        return $row;
	    }else{
	        return null;
	    }
	}

	/**
	 * 玩家列表页总数量查询（为分页查询总页数）
	 */
	public function getCount(){
		$query = $this->getQuery();
		return $query->num_rows();
	}

	/**
	 * 删除银行卡
	 */	
	public function deleteBank($id){
		$u = new stdClass();
		$u->id = $id;
		$u->deleted = self::DELETED;
		if(!$this->update($u)){
			return false;
		}		
		return true;
	}

	/**
	 * 获取玩家最新的一张银行卡
	 */
	public function getUserBank($user_id){
		$this->db->select('*');
		$this->db->from($this->table);
		$this->db->where('user_id', $user_id);
		$this->db->order_by('id', 'ASC'); // DESC
		$rtn = $this->db->get()->last_row();
		if (!$rtn || $rtn->deleted) {
			return array();
		}
		return $rtn;
	}

}
